'use strict';
stareal
    .controller("PriceCategoryList", function ($rootScope,$scope, $api, $stateParams, $alert, $document, localStorageService, $state, $interval,$lazyLoader,$location, $anchorScroll) {
        $scope.currentClassfyId=$stateParams.classId;
        $scope.cityid=$stateParams.cityid;
        $scope.hot=$stateParams.hot;
        $scope.score=$stateParams.score;
        $scope.cityName=$stateParams.cityName;
        $scope.selectID=0;
        $scope.stauts1=false;
        $scope.stauts2=false;
        $scope.stauts3=false;
        if($scope.cityid==''){
            $scope.text1='城市';
        }else{
            $scope.text1=$scope.cityName;
        }
        if($scope.hot==''){
            $scope.text2='热门';
        }else if($scope.hot==1){
            $scope.text2='最新';
        }else if($scope.hot==2){
            $scope.text2='热门';
        }
        if($scope.score==''){
            $scope.text3='评分';
        }else if($scope.score==1){
            $scope.text3='从高到低';
        }else if($scope.score==2){
            $scope.text3='从低到高';
        }
        var h=$(window).height()-3.0*parseFloat(document.documentElement.style.fontSize)+"px";
        $("#wrapper_container").height(h);
        // 分类更多
        $scope.getMoreclassifyli=function(){
            if($scope.currentClassfyId=='-1'){
                $scope.recommendedgoods = new $lazyLoader("app/good/classifyid",
                    {kindid:"",name:"",cityid:$scope.cityid,hot:$scope.hot,score:$scope.score}, true);
                $scope.recommendedgoods.nextPage();
            }else{
                $scope.recommendedgoods = new $lazyLoader("app/good/classifyid",
                    {kindid:$scope.currentClassfyId,name:"",cityid:$scope.cityid,hot:$scope.hot,score:$scope.score}, true);
                $scope.recommendedgoods.nextPage();
            }
        }
        var refresh = function(){
            $state.go('main.price_CategoryList',{classId:$scope.currentClassfyId,cityid:$scope.cityid,hot:$scope.hot,score:$scope.score,cityName:$scope.cityName},true);
        };
        // 分类列表
        $api.get("app/good/classifylist",{}, true)
            .then(function(ret){
                var data=ret.data;
                var obj={id:'0',img:'',key:'-1',value:'全部'};
                data.unshift(obj);
                for(var i=0;i<data.length;i++){
                    if(data[i].key==$scope.currentClassfyId){
                        $scope.currentIndex=i;
                    }
                }
                $scope.classifylistids = data;
                $scope.getMoreclassifyli();
                $scope.getCureenCity();
            },function(err){
                $alert.show(err);
            })

          //获取城市  app/city/list
        $scope.getCureenCity=function(){
            $api.get("app/city/list",{}, true)
                .then(function(ret){
                  $scope.saiCities=ret.data;
                },function(err){
                    $alert.show(err);
                })
        }
        // 点击导航栏
        $scope.switch = function(kind,index){
            //console.log($stateParams);
            $scope.currentClassfyId=kind;
            $scope.currentIndex=index;
            // console.log(kind);
            refresh();

        };

        $scope.$on("navFinishRender",function(){
            $('#demo05').navbarscroll({
                defaultSelect:$scope.currentIndex,

            });
        })

    //    下拉分类
        $scope.switchnavSelect=function(idnx,status){
            $scope.selectID=idnx;
            if($scope.selectID==1){
                $scope.stauts2=false;
                $scope.stauts3=false;
                if($scope.stauts1==false){
                    $scope.stauts1=true;
                }else{
                    $scope.stauts1=false;
                }
            }else if($scope.selectID==2){
                $scope.stauts1=false;
                $scope.stauts3=false;
                if($scope.stauts2==false){
                    $scope.stauts2=true;
                }else{
                    $scope.stauts2=false;
                }
            }else if($scope.selectID==3){
                $scope.stauts1=false;
                $scope.stauts2=false;
                if($scope.stauts3==false){
                    $scope.stauts3=true;
                }else{
                    $scope.stauts3=false;
                }
            }
        }
        //选中筛选的条件
        $scope.changesnav=function(idnx,text,cid){
            $scope.selectID=idnx;
            if($scope.selectID==1){
                $scope.stauts1=false;
                $scope.stauts2=false;
                $scope.stauts3=false;
                $scope.text1=text;
                $scope.cityid=cid;
                $scope.cityName=text;
                refresh();
            }else if($scope.selectID==2){
                $scope.stauts1=false;
                $scope.stauts2=false;
                $scope.stauts3=false;
                $scope.text2=text;
                $scope.hot=cid;
                refresh();
            }else if($scope.selectID==3){
                $scope.stauts1=false;
                $scope.stauts2=false;
                $scope.stauts3=false;
                $scope.text3=text;
                $scope.score=cid;
                refresh();
            }
        }
        $scope.sortscity=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','R','S','T','U','V','W','X','Y','Z'];
        $scope.gotoBottom = function(id) {
            //   console.log(id);
            // 将location.hash的值设置为
            // 你想要滚动到的元素的id
            $location.hash(id);

            // 调用 $anchorScroll()
            $anchorScroll();
        };

    })




